//
// Copyright (c) 2011, Peter Lane
// Licensed under the Academic Free License version 3.0

package fan.swtChartWrapper;

import fan.fwt.*;
import fan.gfx.Color;
import fan.sys.*;
import org.eclipse.swtchart.IBarSeries;
import org.eclipse.swtchart.ISeries;

public class BarSeriesPeer extends SeriesPeer {

  public static BarSeriesPeer make (fan.swtChartWrapper.BarSeries self) throws Exception {
    BarSeriesPeer peer = new BarSeriesPeer ();
    ((Series)self).peer = peer; // override base class's peer field
    return peer;
  }

  public void setISeries (ISeries series) {
    _series = series;
    _pointFormat.peer.setILabel (_series.getLabel ());
    _xErrorBar.peer.setIErrorBar (_series.getXErrorBar ());
    _yErrorBar.peer.setIErrorBar (_series.getYErrorBar ());
    setYPoints (_points);
    ((IBarSeries)_series).setBarColor (Fwt.get().color(_colour));
    ((IBarSeries)_series).setBarPadding ((int)_padding);
    _series.enableStack (_enableStack);
  }

  private List _points;
  public List points (fan.swtChartWrapper.BarSeries self) {
    return _points;
  }
  public void points (fan.swtChartWrapper.BarSeries self, List points) {
    _points = points.dup ();
    if (_series != null) setYPoints(_points);
  }

  private Color _colour = Color.blue;
  public Color color (fan.swtChartWrapper.BarSeries self) { return _colour; }
  public void color (fan.swtChartWrapper.BarSeries self, Color v) {
    _colour = v;
    if (_series != null) ((IBarSeries)_series).setBarColor (Fwt.get().color(_colour));
  }  

  private long _padding = 20;
  public long padding (fan.swtChartWrapper.BarSeries self) { return _padding; }
  public void padding (fan.swtChartWrapper.BarSeries self, long v) {
    if (v <= 0) // lower value for padding is 0
      _padding = 0;
    else if (v >= 100) // upper value for padding is 100
      _padding = 100;
    else 
      _padding = v;
    if (_series != null) ((IBarSeries)_series).setBarPadding ((int)_padding);
  }

  public ISeries.SeriesType type () { return ISeries.SeriesType.BAR; }
}
